<template>
	<view class="container">
		<image class="logo" :src="static+'/logo.png'"></image>
		<view class="form_unit">
			<view class="form_label">原密码</view>
			<input class="inputtext" type="text" password="true" data-name="oldpwd" placeholder="请输入原来登录密码" @input="input_"/>
		</view>
		<view class="form_unit">
			<view class="form_label">新登录密码</view>
			<input class="inputtext" type="text" password="true" data-name="pwd" placeholder="请输入新登录密码" @input="input_"/>
		</view>
		<view class="form_unit">
			<view class="form_label">再次输入密码</view>
			<input class="inputtext" type="text" password="true" data-name="again" placeholder="再次输入一次登录密码" @input="input_"/>
		</view>
		<!-- <view class="form_unit">
			<view class="form_label">+86</view>
			<input class="inputtext" type="number" data-name="phone" @input="input_" placeholder="请输入登录用手机号码"/>
		</view>
		<view class="form_unit">
			<input class="verify_input" type="number" :value="verify" data-name="verify" @input="input_" placeholder="请输入验证码"/>
			<view class="number" v-on:click="get_verify_code" v-if="second==60">{{number}}</view>
			<view class="number" v-else>{{number}}</view>
		</view> -->
		<view class="operate_login">
			<view class="login_button" v-on:click="register_submit">确认修改</view>
		</view>
	</view>
</template>
<style>
	page{background: #F5F5F5;}
	.container{background: #F5F5F5;display: flex;flex-direction: column;justify-content: space-between;align-items: center;}
	.logo{width:200upx;height:200upx;margin-top:100upx;}
	.form_unit{width: 75%;margin:10upx 12.5%;border-bottom: 1px dashed #282828;display: flex;justify-content: space-between;align-items: center;height: 80upx;}
	.form_label{width:33%;font-size: 28upx;color: #282828;text-align: center;border-right: 1px solid #282828;}
	.inputtext{font-size: 28upx;text-align: left;width: 65%;color: #282828;}
	.verify_input{font-size: 28upx;text-align: center;width: 45%;color: #282828;}
	.number{width:35%;height: 60upx;line-height: 60upx;font-size: 28upx;background:#419CAF;border-radius: 10upx;text-align: center;}
	.operate_login{width: 75%;margin:10upx 12.5%;height: 80upx;display: flex;justify-content: center;align-items: center;}
	.login_button{width:96%;height: 80upx;font-size: 30upx;line-height: 80upx;background-image: linear-gradient(#43eac9, #24c3a4);color: #282828;border-radius: 40upx;text-align: center;}
	.wechat_button{width:48%;height: 80upx;font-size: 30upx;border-radius: 40upx;display: flex;justify-content: center;align-items: center;color: #282828;text-decoration: underline;}
	.rule{width: 75%;margin:10upx 12.5%;height: 80upx;display: flex;justify-content: flex-start;align-items: center;}
	.rule_text{font-size: 28upx;color: #282828;margin-left: 10upx;width:80%;}
	.rule_text text{text-decoration: underline;color: #007AFF;}
	.service{font-size: 28upx;width:100%;text-align: center;position: fixed;bottom: 20upx;color: #282828;}
</style>
<script>
	export default {
		data() {
			return {
				phone:'',
				oldpwd:'',
				password:'',
				again:'',
				timer :'',
				second:60,
				device_id:'',
				verify:'',
				code:'',
				number:'获取验证码',
				status:0,
				url: getApp().globalData.url,
				static:getApp().globalData.static
			}
		},
		onLoad() {
			// const devideManager = uni.requireNativePlugin("HXR-UniqueDeviceId")
			// this.device_id = devideManager.getDeviceId();
			// console.log("设备码："+device_id);
			// var res = uni.getSystemInfoSync();
			// console.log("IMEI: "+plus.device.imei);  
		},
		methods: {
			get_verify_code:function(){
				var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
				if(!reg_tel.test(this.phone))
				{
					uni.showToast({
						title:'不是有效的手机号码',
						duration:1000
					})
				}
				else
				{
					if(this.second==60)
					{
						uni.request({
							url: this.url+"/wechat_get_msm_code",
							data: {phone:this.phone},
							header: {
							  'Content-Type': 'application/json'
							},
							success: function (res) 
							{
								console.log(res);
							}
						})
					}
					var that = this;
					this.timer = setInterval(()=>{
						if(that.second>0)
						{
							that.second--;
							that.number = that.second+"秒后再获取";
						}
						else
						{
							that.second = 60;
							that.number = "获取验证码";
							clearInterval(that.timer);
							that.timer = null;
						}
					},1000)
				}
			},
			register_submit:function()
			{
				if(this.password.length<6)
				{
					uni.showToast({
						title:'密码不能低于6位',
					})
				}
				else if(this.password==this.again)
				{
					var that = this;
					var member_id = uni.getStorageSync("member_id");
					uni.request({
						url: this.url+'/wechat_udpate_member_pwd', 
						method:"POST",
						data: {oldpwd:this.oldpwd,password:this.password,member_id:member_id},
						header: {'Content-Type': 'application/x-www-form-urlencoded'},
						success: (res) => {
							console.log(res.data);
							if(res.data.status==1)
							{
								that.st = 1;
								uni.showToast({
									title:"修改成功",
									duration:2000
								})
								uni.redirectTo({url:'/pages/member/system'});
							}
							else
							{
								uni.showModal({
									title:"操作提示",
									content:res.data.msg,
									showCancel:false
								})
							}
						}
					});
				}
				else
				{
					uni.showToast({
						title:"重复密码不正确",
						duration:1000
					})
				}
			},
			input_:function(e)
			{
				if(e.currentTarget.dataset.name=="verify")
				{
					this.verify   = e.detail.value;
				}
				if(e.currentTarget.dataset.name=="phone")
				{
					this.phone = e.target.value;
				}
				if(e.currentTarget.dataset.name=="oldpwd")
				{
					this.oldpwd = e.target.value;
				}
				if(e.currentTarget.dataset.name=="pwd")
				{
					this.password = e.target.value;
				}
				if(e.currentTarget.dataset.name=="again")
				{
					this.again = e.target.value;
				}
				if(e.currentTarget.dataset.name=="code")
				{
					this.code = e.target.value;
				}
			}
		}
	}
</script>


